package _73

/*
时间复杂度：O()
空间复杂度：O()

*/

var m = map[byte][2]int{
	'R': {0, 1},
	'L': {0, -1},
	'U': {-1, 0},
	'D': {1, 0},
}

func executeInstructions(n int, startPos []int, s string) []int {
	result := make([]int, 0)
	var run func(st string) int
	run = func(st string) int {
		count := 0
		x, y := startPos[0], startPos[1]
		for i, _ := range st {
			pos := m[st[i]]
			x += pos[0]
			y += pos[1]
			if x < 0 || x >= n || y < 0 || y >= n {
				break
			}
			count++
		}
		return count
	}
	for i, _ := range s {
		result = append(result, run(s[i:]))
	}
	return result
}
